



public class NormalList<T> extends List<T> implements Iterable<T> {
	
	public Iter<T> iterator() {
		return new ListIterator();
	}
	
	public NormalList<T> clone() {
		NormalList<T> l = new NormalList<T>();
		Iter<T> it = iterator();
		while(it.hasNext()) {
			l.add(it.next());
		}
		return l;
	}
	
	protected class ListIterator implements Iter<T> {
		private Node current = getHead();
		private Node next = null;
		private Node previous = null;
		private boolean isFirst = true;
		
		protected ListIterator() {
			if(current != null) {
				next = current.next;
				previous = current.previous;
			}
		}
		
		private boolean endOfList = false;
		private boolean beginOfList = false;
		
		@Override
		public T next() {
			if(isFirst) {
				isFirst = false;
				return (current == null) ? null : current.element;
			}
			if(next == null) {
				endOfList = true;
				return null;
			}
			if(beginOfList) {
				beginOfList = false;
				return current.element;
			}
			current = next;
			previous = current.previous;
			next = current.next;
			return current.element;
		}

		@Override
		public T previous() {
			if(isFirst) {
				isFirst = false;
				return (current == null) ? null : current.element;
			}
			if(previous == null) {
				beginOfList = true;
				return null;
			}
			if(endOfList) {
				endOfList = false;
				return current.element;
			}
			current = previous;
			previous = current.previous;
			next = current.next;
			return current.element;
		}

		@Override
		public boolean hasNext() {
			if(current == null) {
				return false;
			}
			if(isFirst) {
				return (current != null);
			}
			return (current.next != null);
		}

		@Override
		public boolean hasPrevious() {
			if(current == null) {
				return false;
			}
			if(isFirst) {
				return (current != null);
			}
			return (current.previous != null);
		}
	}
}
